package com.stars.empoly.activity

import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.githang.statusbar.StatusBarCompat
import com.hwangjr.rxbus.annotation.Subscribe
import com.hwangjr.rxbus.annotation.Tag
import com.qmuiteam.qmui.kotlin.onClick
import com.qmuiteam.qmui.widget.tab.QMUITab
import com.qmuiteam.qmui.widget.tab.QMUITabBuilder
import com.stars.empoly.base.MBTabActivity
import com.stars.empoly.config.ConfigRx
import com.stars.empoly.databinding.ActivityMyIncomeBinding
import com.stars.empoly.fragment.IncomeListFragment
import com.stars.empoly.fragment.WithListFragment
import com.stars.empoly.vmodel.MyIncomeVModel
import com.trailer.base.utils.UiSwitch
import com.trailer.base.utils.UiUtils

/**
 *on 2021/5/9
 */
class MyIncomeActivity:  MBTabActivity<MyIncomeVModel, ActivityMyIncomeBinding>()  {

    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
       // StatusBarCompat.setStatusBarColor(this, Color.parseColor("#ED6D30"))
        StatusBarCompat.setStatusBarColor(this, Color.parseColor("#00000000"))


        setShow()
        vm.getHeadInfo()

    }

    override fun listeners() {
        super.listeners()

        binding.imgBack.onClick {
            finish()
        }
        binding.butWithdraw.onClick {
            //提现
            UiSwitch.single(this, WithdrawActivity::class.java)

        }
    }


    private fun setShow() {

        if (Build.VERSION.SDK_INT < Build.VERSION_CODES.KITKAT) { //不支持沉浸式状态栏
        } else {
            //获取状态栏的高度
            val statusBarHeight: Int = UiUtils.getStatusBarHeight()

            //动态设置高度  tv
            val params = binding.tv.getLayoutParams()
            //获取当前控件的布局对象
            //params.height=UiUtils.dp2dip(getContext(), statusBarHeight);//设置当前控件布局的高度
            params.height = statusBarHeight
            binding.tv.layoutParams = params //将设置好的布局参数应用到控件中
            binding.tv.visibility = View.VISIBLE
        }

    }
    override fun vmClass(): Class<MyIncomeVModel> {
        return MyIncomeVModel::class.java
    }
    override fun createTabs(tabBuilder: QMUITabBuilder): Array<QMUITab> {
        val component = tabBuilder
                .setText("收益明细")
                .build(context())

        val two = tabBuilder
                .setText("提现记录")
                .build(context())


        return arrayOf(component,two)
    }

    override fun binding(): ActivityMyIncomeBinding {
       return ActivityMyIncomeBinding.inflate(layoutInflater)
    }

    override fun getPageItem(position: Int): Fragment {
        when (position) {
            0 -> {
                return IncomeListFragment()
            }

            1 -> {
                return WithListFragment()

            }


            else->{
                return IncomeListFragment()
            }

        }
    }

    override fun getPageCount(): Int {
       return 2
    }

    override fun title(): String? {
        return null
    }

    override fun transluent(): Boolean {
        return true
    }
    override val isRxbus: Boolean
        get() =true

    @Subscribe(tags = [Tag(ConfigRx.REFRESH_MONEY)])
    fun setRefreshMoney(position: String) {
        vm.getHeadInfo()
    }


}
